export function toThousands(num) {
	var result = '',
		counter = 0;
	num = (num || 0).toString();
	let defaultNum = num;
	if(defaultNum.indexOf("-") != -1){
		num = num.slice(1,num.length)
	}
	for (var i = num.length - 1; i >= 0; i--) {
		counter++;
		result = num.charAt(i) + result;
		if (!(counter % 3) && i != 0) {
			result = ',' + result;
		}
	}
	return defaultNum.indexOf("-") ==-1 ? result:'-'+result;
}

export function chinaFormat(num){
	let result = "";
	let counter = 0;
	const arr = ['万', '亿','兆','京','垓','秭','穰','沟','涧','正','载']
	num = (num || 0).toString();
	for (var i = num.length - 1; i >= 0; i--) {
		counter++;
		result = num.charAt(i) + result;
		if (!(counter % 4) && i != 0) {
			result = ',' + result;
		}
	}
	const resArr = result.split(",")
	const resArrTemp = [...resArr].slice(0,resArr.length-1)
	console.log(resArr);
	console.log(resArrTemp);
	let chinaRes = ""
	let co = 0;
	for(var i = resArrTemp.length - 1; i>=0; i--){
		if(co > (arr.length-1)){
			// console.log(resArrTemp[i],co);
			chinaRes = resArrTemp[i] + ',' + chinaRes
		}else{
			// console.log(resArrTemp[i],arr[co]);
			chinaRes =  resArrTemp[i] +arr[co] + chinaRes
		}
		co++
	}
	console.log(chinaRes+resArrTemp[resArrTemp.length-1]);
}
// 20亿0050万2300 20，0500，2300